<template>
  <view v-if="hasPermission">
    <slot></slot>
  </view>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import permission from '@/permission';

interface Props {
  value: string | string[];
  any?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  any: false,
});

const hasPermission = computed(() => {
  if (!props.value) {
    return true;
  }

  // 将单个权限字符串转换为数组
  const permissions = Array.isArray(props.value) ? props.value : [props.value];
  console.log('严格权限：', permission.anyPermission(permissions))
  console.log('普通权限：', permission.allPermission(permissions))
  
  // 根据 any 属性选择权限检查策略
  return props.any
    ? permission.anyPermission(permissions)
    : permission.allPermission(permissions);
});
</script>

